﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FileSystem.Models;

namespace FileSystem.Services.IServices {
    /// <summary>
    /// 用户存储接口
    /// </summary>
    public interface IUserStorage {
        /// <summary>
        /// 初始化用户存储
        /// </summary>
        Task InitializeAsync();

        /// <summary>
        /// 用户存储是否已经初始化
        /// </summary>
        bool IsInitialized();

        /// <summary>
        /// 增加用户
        /// </summary>
        /// <param name="user">要添加的用户</param>
        Task AddAsync(User user);

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="user">要删除的用户</param>
        Task RemoveAsync(User user);

        /// <summary>
        /// 修改用户属性
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="property">属性</param>
        /// <param name="newContent">新值</param>
        Task ModifyProperty(User user, UserConst.Property property,
            string newContent);

        /// <summary>
        /// 修改用户属性
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="property">属性</param>
        /// <param name="newContent">新值</param>
        Task ModifyProperty(User user, UserConst.Property property,
            int newContent);

        /// <summary>
        /// 根据用户名获得一个用户
        /// </summary>
        /// <param name="userName">用户名</param>
        Task<User> GetUser(string userName);

        /// <summary>
        /// 获得所有用户
        /// </summary>
        Task<IList<User>> GetUsers();

        /// <summary>
        /// 判断用户是否存在
        /// </summary>
        /// <param name="userName">用户名</param>
        Task<bool> Exist(string userName);
    }

    /// <summary>
    /// 用户存储常量
    /// </summary>
    public static class UserStorageConstants
    {
        /// <summary>
        /// 默认的用户数据库版本号。
        /// </summary>
        public const int DefaultVersion = 0;

        /// <summary>
        /// 用户数据库版本号。
        /// </summary>
        public const int Version = 1;

        /// <summary>
        /// 用户数据库版本号键。
        /// </summary>
        public const string VersionKey = nameof(UserStorageConstants) +
            "." + nameof(Version);
    }
}